#include "hud.h"

#include "SDL/SDL_gfxPrimitives.h"

Hud::Hud() :
	gdata( Gamedata::getInstance() ),
	io( IOManager::getInstance() ),
	screen(io.getScreen()),
	player(NULL),
	visible(1),
	fps(0)
{
	
}

Hud::~Hud()
{
	
}

void Hud::draw() const
{
	int off = 20;
	char msg[512];
	if(visible)
	{
		int x = 18;
		int y = 18;
		int x2 = 277+18;
		int y2 = 20*14+2+18;
		boxRGBA(screen, x,y,x2,y2,255,255,255,100);

		io.printMessageAt("+--------+-----------------------+",20,off);
		io.printMessageAt("|  Key   |       Command         |",20,off+=20);
		io.printMessageAt("+--------+-----------------------+",20,off+=20);
		io.printMessageAt("| Escape | Exit game             |",20,off+=20);
		io.printMessageAt("|   q    | Exit game             |",20,off+=20);
		io.printMessageAt("|  Tab   | Toggle HUD            |",20,off+=20);
		io.printMessageAt("|   t    | Cycle object to track |",20,off+=20);
		io.printMessageAt("|   c    | Track the character   |",20,off+=20);
		io.printMessageAt("| Space  | Jump                  |",20,off+=20);
		io.printMessageAt("|   a    | Move left             |",20,off+=20);
		io.printMessageAt("|   d    | Move right            |",20,off+=20);
		io.printMessageAt("|   m    | Menu/Pause            |",20,off+=20);
		io.printMessageAt("|   g    | God Mode              |",20,off+=20);
		io.printMessageAt("+--------+-----------------------+",20,off+=20);
	}

	boxRGBA(screen,0,screen->h-20,screen->w,screen->h,255,255,255,100);
	sprintf(msg,"Score: %d     Health: %d",player->getScore(), player->getHealth());
	io.printMessageAt(msg,20,screen->h-20);

	sprintf(msg,"%d fps",fps);
	io.printMessageAt(msg,screen->w-100,screen->h-20);
}

void Hud::update(int fps)
{
	this->fps = fps;
}

void Hud::toggle()
{
	visible ^= 1;
}

void Hud::setPlayer(Player *p)
{
	player = p;
}
